package cn.mldn.oracle.service.impl;

import java.util.List;

import cn.mldn.oracle.dao.IEmpDAO;
import cn.mldn.oracle.dbc.DatabaseConnection;
import cn.mldn.oracle.factory.DAOFactory;
import cn.mldn.oracle.service.IEmpService;
import cn.mldn.oracle.vo.Emp;

public class EmpServiceImpl implements IEmpService {
	
	private DatabaseConnection dbc = new DatabaseConnection();
	IEmpDAO dao;
	
	public EmpServiceImpl() {
		dao = DAOFactory.getIEmpDAOInstance(dbc.getConnection());
	}
	
	@Override
	public boolean insert(Emp vo) throws Exception {
		try {
			return dao.doCreate(vo);
		} catch (Exception e) {
			throw e;
		} finally{
			dbc.close();
		}
	}

	@Override
	public boolean update(Emp vo) throws Exception {
		try {
			return dao.doUpdate(vo);
		} catch (Exception e) {
			throw e;
		} finally{
			dbc.close();
		}
	}

	@Override
	public boolean delete(Integer id) throws Exception {
		try {
			return dao.doRemove(id);
		} catch (Exception e) {
			throw e;
		} finally{
			dbc.close();
		}	}

	@Override
	public Emp get(Integer id) throws Exception {
		try {
			return dao.findById(id);
		} catch (Exception e) {
			throw e;
		} finally{
			dbc.close();
		}
	}

	@Override
	public List<Emp> list() throws Exception {
		try {
			return dao.findAll();
		} catch (Exception e) {
			throw e;
		} finally{
			dbc.close();
		}
	}

}
